/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "fatfs.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

#include <stdio.h>

#include "w25qxx.h"


/* USER CODE END Includes */

void write_flash(char * filename, uint32_t sector)
{
	int i;
	uint32_t  bytesRead;
	// uint32_t sector;
	uint8_t   buffer[4096];
	
	for(i = 0; i < 4096; i++)	buffer[i] = i;
	
	retSD = f_open(&SDFile, filename, FA_READ);
	if(retSD == FR_OK) {
		printf("open %s OK, res = %d\r\n", filename, retSD);
	} else {
		printf("---> f_open() %s failed, res = %d\r\n", filename, retSD);
	}
	
	// sector = 0;
	for(;;) {
		retSD = f_read(&SDFile, buffer, 4096, &bytesRead);
		if(retSD == FR_OK) {
			printf("read %s  %d bytes OK  sector: %d\r\n", filename, bytesRead, sector);
			W25qxx_EraseSector(sector);
			W25qxx_WriteSector(buffer, sector, 0, 4096);
		} else {
			printf("---> read %s error !!!\r\n", filename);
			return;
		}
		if(bytesRead < 4096) break;
		sector++;
	}
	f_close(&SDFile);
	
}


void write_font(void)
{
	// write_flash("HZK24F", 0 + 24 + 24 + 72 + 160 + 2 + 2);	// 2
	
#if 0
	write_flash("oem2uni.bin", 0);	// 24
	write_flash("uni2oem.bin", 0 + 24);	// 24
	
	write_flash("hzk16k", 0 + 24 + 24);	// 72
	write_flash("hzk24k", 0 + 24 + 24 + 72);	// 160
	
	write_flash("asc16.fnt", 0 + 24 + 24 + 72 + 160);	// 2
	write_flash("asc24", 0 + 24 + 24 + 72 + 160 + 2);	// 2
#endif

}


